﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;

namespace ProjetLabo.Controls
{
    /// <summary>
    /// Logique d'interaction pour ControlTable.xaml
    /// </summary>
    public partial class ControlTable : UserControl
    {

        public const string STATE_UPDATED = "updated";
        public const string STATE_UPDATING = "updating";
        public const string STATE_NEW = "new";
        public const string STATE_DELETE = "delete";

        private DataTable table;
        private String state;
        private Binding source;
        public String State
        {
            get { return state; }
            set { 
                state = value;
                UpdateView();
            }
        }



        public DataTable Table
        {
            get { return table; }
            set { 
                table = value;
                this.title.Text = table.TableName;
                int i=0;
                foreach(DataColumn column in table.Columns)
                {
                    this.RenderModel.RowDefinitions.Add(new RowDefinition()
                    {
                        Height = new GridLength(20)
                    });
                    TextBox blockTName = new TextBox() { Text = column.ColumnName };
                    TextBox blockTType = new TextBox() { Text = column.DataType.Name };
                    Grid.SetColumn(blockTName, 0);
                    Grid.SetColumn(blockTType, 1);
                    Grid.SetRow(blockTName, i);
                    Grid.SetRow(blockTType, i);
                    this.RenderModel.Children.Add(blockTName);
                    this.RenderModel.Children.Add(blockTType);
                    i++;
                }
                
            }
        }

        public ControlTable()
        {
            InitializeComponent();
            TextDecoration textdeco = new TextDecoration();
            Binding source = new Binding();
            

        }

        public void UpdateView()
        {
            switch (state)
            {
                case ControlTable.STATE_UPDATED:
                    this.TableView.BorderBrush = new SolidColorBrush(Colors.Green);
                    break;
                case ControlTable.STATE_UPDATING:
                    this.TableView.BorderBrush = new SolidColorBrush(Colors.Orange);
                    break;
                case ControlTable.STATE_NEW:
                    this.TableView.BorderBrush = new SolidColorBrush(Colors.Blue);
                    break;
                case ControlTable.STATE_DELETE:
                    this.TableView.BorderBrush = new SolidColorBrush(Colors.Red);
                    break;
            }
        }

        
    }

    
}
